package com.net.wanjian.networkhospitalmanager.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.bean.GetHospitalListReturn;
import com.zhy.autolayout.utils.AutoUtils;

import java.net.URLDecoder;
import java.util.zip.Inflater;

/**
 * Description:
 * Created by lidongcai on 17/5/8.
 * Email:  lidongcaiocc@163.com
 */

public class SelectHospitalAdapter extends BaseExpandableListAdapter {
    private Context context;
    private GetHospitalListReturn.DataBean dataBean;

    public SelectHospitalAdapter(Context context, GetHospitalListReturn.DataBean dataBean) {
        this.context = context;
        this.dataBean = dataBean;
    }

    @Override
    public int getGroupCount() {
        return null == dataBean.getDataInfoList() ? 0 :dataBean.getDataInfoList().size();
//        return 5;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
//        return 10;
        return null == dataBean.getDataInfoList().get(groupPosition).getCustomerInfoList() ? 0:dataBean.getDataInfoList().get(groupPosition).getCustomerInfoList().size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return dataBean.getDataInfoList().get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return dataBean.getDataInfoList().get(groupPosition).getCustomerInfoList().get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_select_hospital_group,parent,false);
        }

            TextView textView = (TextView) convertView.findViewById(R.id.item_select_hospital_group_tv);
            textView.setText(URLDecoder.decode(dataBean.getDataInfoList().get(groupPosition).getProvince()));

        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_select_hospital_child,parent,false);
        }

        TextView textView = (TextView) convertView.findViewById(R.id.item_select_hospital_child_tv);
        textView.setText(URLDecoder.decode(dataBean.getDataInfoList().get(groupPosition).getCustomerInfoList().get(childPosition).getCustomerInfoName()));
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    public void setListData(GetHospitalListReturn.DataBean dataBean){
        this.dataBean = dataBean;
        notifyDataSetChanged();
    }
}
